package eu.scillman.net.tcp;

import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

import eu.scillman.interfaces.ICommConstants;

/**
 * http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html
 * http://systembash.com/content/a-simple-java-tcp-server-and-tcp-client/
 * http://ashishmyles.com/tutorials/tcpchat/
 */

public class ServerSun {
	public static void main(String args[]) {
		String data = "Toobie ornaught toobie";
		try {
			ServerSocket srvr = new ServerSocket(54016);
			srvr.setSoTimeout(ICommConstants.CONNECTION_TIMEOUT);
			
			Socket skt = srvr.accept();
			System.out.print("Server has connected!\n");
			PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
			System.out.print("Sending string: '" + data + "'\n");
			out.print(data);
			out.close();
			skt.close();
			srvr.close();
		}
		catch (Exception ex) {
			System.out.println(ex.toString() + ": " + ex.getMessage());
			System.out.print("Whoops! It didn't work!\n");
		}
	}
}
